package vboot.app.module.de.supp.main;

import vboot.core.common.api.R;
import vboot.core.common.dao.Sqler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import vboot.core.module.ass.num.main.AssNumMainService;
import vboot.core.module.mon.log.oper.Oplog;

//供应商主信息接口
@RestController
@RequestMapping("de/supp/main")
public class DeSuppMainApi {

    @Oplog("查询供应商分页数据")
    @GetMapping
    public R get(String name) {
        Sqler sqler = new Sqler("de_supp_main");
        sqler.addLike("t.name", name);
        sqler.addSelect("t.addre,t.senum,t.notes");
        return R.ok(service.findPageData(sqler));
    }

    @Oplog("查询供应商单个详情")
    @GetMapping("one/{id}")
    public R getOne(@PathVariable String id) {
        DeSuppMain main = service.findOne(id);
        return R.ok(main);
    }

    @Oplog("新增供应商")
    @PostMapping
    public R post(@RequestBody DeSuppMain main) {
        main.setSenum(numService.getNum("SUPP"));//设置供应商流水号
        return R.ok(service.insert(main));
    }

    @Oplog("更新供应商")
    @PutMapping
    public R put(@RequestBody DeSuppMain main) {
        return R.ok(service.update(main));
    }

    @Oplog("删除供应商")
    @DeleteMapping("{ids}")
    public R delete(@PathVariable String[] ids) {
        return R.ok(service.delete(ids));
    }

    @Autowired
    private DeSuppMainService service;

    @Autowired
    private AssNumMainService numService;

}
